package cate.game.mail.po;

import cp.solution.business.game.component.NoticeParam;
import cate.game.res.MixRes;
import cate.game.role.mail.Mail;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MailBuilder {

    /** 邮件标题 */
    private String title;

    public MailBuilder setTitle(String title) {
        this.title = title;
        return this;
    }

    /** 邮件内容ID */
    private int contentId;

    public MailBuilder setContentId(int contentId) {
        this.contentId = contentId;
        return this;
    }

    /** 邮件内容参数 */
    private List<NoticeParam> paramList;

    public MailBuilder setNoticeParamList(List<NoticeParam> paramList) {
        this.paramList = paramList;
        return this;
    }

    public MailBuilder setNoticeParamList(NoticeParam... params){
        if(params != null){
            this.paramList = Arrays.asList(params);
        }
        return this;
    }

    public MailBuilder setParamList(List<Object> paramList){
        if(paramList != null){
            List<NoticeParam> params = new ArrayList<>();
            for(Object param : paramList){
                params.add(new NoticeParam(param));
            }
            this.paramList = params;
        }
        return this;
    }

    /** 直接设置为完全的文本内容 */
    public MailBuilder setContent(String content) {
        this.contentId = 0;
        this.paramList = new ArrayList<>();
        this.paramList.add(new NoticeParam(content));
        return this;
    }

    /** 奖励 */
    private MixRes reward;

    public MailBuilder setReward(MixRes reward) {
        this.reward = reward;
        return this;
    }

    public MailBuilder setRewardConf(String rewardConf) {
        this.reward = new MixRes(rewardConf);
        return this;
    }

    /** 因为什么操作得到该邮件 */
    private int operation;

    public MailBuilder setOperation(int operation) {
        this.operation = operation;
        return this;
    }

    /** 操作子类型 */
    private int operationSub;

    public MailBuilder setOperationSub(int operationSub) {
        this.operationSub = operationSub;
        return this;
    }

    public Mail build() {
        Mail mail = new Mail();
        mail.title = this.title;
        mail.contentId = this.contentId;
        mail.paramList = this.paramList == null ? null : new ArrayList<>(this.paramList);
        mail.reward = this.reward;
        mail.createTime = System.currentTimeMillis();
        mail.operation = this.operation;
        mail.operationSub = this.operationSub;
        mail.read = false;
        mail.got = false;
        return mail;
    }
}
